package HaiBao;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();

        double baseWith = 702;
        double baseHeight = 973;

        String haiBao = Math.class.getResource("/HaiBao").getPath();
        System.out.println(haiBao);
        File file = new File(haiBao + "/background.png");
        InputStream inputStream = new FileInputStream(file);
        BufferedImage bufferedImage = PosterUtil.drawInit(null, inputStream);

        double width = bufferedImage.getWidth();
        double height = bufferedImage.getHeight();

        // 将头像图片处理成圆形
        String headUrl = "http://123.57.109.183:8081/home/ys/uploadFile/logo/20221113/20221113140044-photo_release1668319230730.png";
        BufferedImage head = PosterUtil.drawImgToCircle(headUrl, m.getXpx(84));
        // 画 微信头像
        //PosterUtil.drawImage(bufferedImage, head, m.getXpx(309), m.getXpx(56));
        PosterUtil.drawCenterImage(bufferedImage, head, m.getXpx(56));

        File file2 = new File(haiBao + "/background2.png");
        BufferedImage read = ImageIO.read(file2);
        /*PosterUtil.drawImage(bufferedImage, read, 1053 / 320 * 15, 1460 / 480 * 125);*/
        int back2x = 31;
        int back2y = 251;
        PosterUtil.drawImage(bufferedImage, read, m.getXpx(back2x), m.getYpx(back2y));

        Color color = new Color(255, 242, 222);
        String companyName = "万达商场有限责";
        int fontSize = m.getXpx(34);

        //PosterUtil.drawWords(bufferedImage, companyName, false, "苹方-简 中黑体", color, fontSize, left, m.getYpx(164 + 28), 1000, 84);
        PosterUtil.drawCenterWords(bufferedImage, companyName, "苹方-简 中黑体", color, fontSize, m.getYpx(164 + 28), 1000, 84);
        PosterUtil.drawCenterWords(bufferedImage, "消防栓", "黑体", null, 35, m.getYpx(251 + 377), 1000, 84);

        PosterUtil.drawWords(bufferedImage, "编号：",  "黑体", null, 30, m.getXpx(41 + back2x), m.getYpx(back2y + 454), 1000, 84);
        PosterUtil.drawWords(bufferedImage, "位置：",  "黑体", null, 30, m.getXpx(41 + back2x), m.getYpx(back2y + 514), 1000, 84);
        PosterUtil.drawWords(bufferedImage, "属性：",  "黑体", null, 30, m.getXpx(41 + back2x), m.getYpx(back2y + 574), 1000, 84);
        PosterUtil.drawRightWords(bufferedImage, "XF-F1-01", "黑体", null, 30, m.getXpx(41 + 31), m.getYpx(back2y + 454), 1000, 84);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "png", os);
        File file1 = new File("d:\\image.png");
        FileOutputStream fos = new FileOutputStream(file1);
        fos.write(os.toByteArray());
        fos.close();

    }

    int getXpx(int x) {
        return PosterUtil.getRealPx(702.0, 1053.0, x);
    }

    int getYpx(int y) {
        return PosterUtil.getRealPx(973.0, 1460.0, y);
    }


}
